package com.akina.matchsystem.config;


import org.springframework.stereotype.Component;

import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;

@Component
public class HttpSessionConfigurator extends ServerEndpointConfig.Configurator implements ServletRequestListener {

    /**
     * 监听， 把httpsession放入，不是很理解
     * @param sre
     */
    @Override
    public void requestInitialized(ServletRequestEvent sre) {
       HttpSession session = ((HttpServletRequest) sre.getServletRequest()).getSession();
    }

    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
        HttpSession httpSession = (HttpSession) request.getHttpSession();
        //sec 终端    这是个map<String , object>类型。把请求的名字放进去
        sec.getUserProperties().put(HttpSession.class.getName(),httpSession);
    }

    @Override
    public void requestDestroyed(ServletRequestEvent sre) {
    }
}
